Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjustments to core suspender #5075

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

ab9rf
Copy link
Member

@ab9rf ab9rf commented Dec 3, 2024

this is an attempted step to improve semantics around core suspenders. this does not actually resolve #5074 but it is intended as a step toward doing so

@ab9rf
Copy link
Member Author

ab9rf commented Dec 3, 2024

with the last commit this now does resolve #5074

i've validated it on windows but needs testing on linux

test procedure:

  • launch game.
  • in console enter a nonsense command, should quickly respond "blah is not a recognized command"
  • in launcher, enter lua "while(true) do end". this will freeze the launcher as this is an infinite loop
  • in console, enter a nonsense command, should (after a brief pause) respond "Cannot acquire core lock in helpdb.get_commands" followed by "blah is not a recognized command"
  • in console, enter kill-lua. the console should emit a lua traceback, and the launcher should unfreeze and also show the traceback
  • in console, enter a nonsense command, should quickly respond "blah is not a recognized command"

@ab9rf ab9rf requested a review from lethosor December 3, 2024 17:56
@ab9rf
Copy link
Member Author

ab9rf commented Dec 3, 2024

@dhthwy has confirmed that this works on linux, so i'm releasing it for review

@ab9rf ab9rf marked this pull request as ready for review December 3, 2024 18:28
@ab9rf
Copy link
Member Author

ab9rf commented Dec 4, 2024

thanks again to @NicksWorld for their invaluable help on this PR

myk002 added a commit to myk002/dfhack that referenced this pull request Dec 6, 2024
to reduce danger of deadlocking
will be reverted in DFHack#5075
library/include/Core.h Outdated Show resolved Hide resolved
@ab9rf ab9rf marked this pull request as draft December 13, 2024 06:09
ab9rf and others added 3 commits December 13, 2024 19:21
this is an attempted step to improve semantics around core suspenders. this does not actually resolve DFHack#5074 but it is intended as a step toward doing so
this switches the core lock to a recursive timed mutex, uses a `try_lock_for` in `CoreSuspenderBase` and changes `help_helper` and `get_commands` over to using conditional locks to avoid a hang in the event that a core lock cannot be acquired in these methods

i also moved some repeated code into protected/private methods in both `CoreSuspenderBase` and `CoreSuspender` to mitigate DRY, which also massively improves readability

h/t to @NicksWorld for their help in figuring out the required semantics

Co-Authored-By: Nicholas McDaniel <[email protected]>
Drastically simplify CoreSuspender API:
* remove access to state manipulation
* add ConditionalCoreSuspender subclass for conditional locks
* fix various errors around use of an explicit core argument when creating a CoreSuspender
to satisfy gcc's order warning

i will shortly submit a PR to add `/w15038` to the msvc configuration so msvc will also catch these warnings going forward
@ab9rf ab9rf marked this pull request as ready for review December 14, 2024 02:36
@ab9rf
Copy link
Member Author

ab9rf commented Dec 14, 2024

The last batch of changes drastically simplify the CoreSuspender API by removing consumer access to CoreSuspender state, adding a ConditionalCoreSuspender subclass that provides a conditional locking mechanic, fixes various errors around use of an explicit core argument when creating a CoreSuspender, which required having CoreSuspenderBase hold a reference to the core used to initialize it. I also changed the explicit-core constructors to use a Core& instead of a Core*

removed the local `isLocked` member from `CoreSuspenderBase` as it is redundant with `owns_lock()` from `std::unique_lock`

h/t to @NicksWorld for pointing this out

Co-Authored-By: Nicholas McDaniel <[email protected]>
library/include/Core.h Outdated Show resolved Hide resolved
library/include/Core.h Outdated Show resolved Hide resolved
no point in calling `owns_lock` twice
@myk002
Copy link
Member

myk002 commented Dec 18, 2024

I'm not certain of the full effect of this change, but the changes look reasonable to merge for practical testing

@myk002
Copy link
Member

myk002 commented Dec 19, 2024

@lethosor any (blocking) concerns before we merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review In Progress
Development

Successfully merging this pull request may close these issues.

console hang if user makes a typo while lua is busy
4 participants